# 构建模型
class poly_model(nn.Module):
    def __init__(self):
        super(poly_model,self).__init__()
        self.fc = nn.Linear(in_features = 2, out_features = 1)
    def forward(self,x):
        out = self.fc(x)
        return out
model = poly_model()
criterion = nn.MSELoss()
optimizer = torch.optim.SGD(model.parameters(),lr=0.001)
for epoch in range(3000):
    out = model(x_input)
    loss = criterion(out, y_true)
    print_loss = loss.item()

    # backward
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()
    print('epoch is {} loss is {}'.format(epoch, print_loss))
print(model.fc.weight.data.numpy()[0]) # 训练后x1,x2的权重
print(model.fc.bias.data.numpy())  
